package objectdemo;

class Person
{
	private String name;
	private int age;
	
	public  Person()
	{
		
	}
	public  Person(String name,int age)
	{
		setName(name);
		setAge(age);
	}
	public String getInfo()
	{
		return null;
		
	}
	public String getName()
	{
		return name;
	}
	public void setName(String name)
	{
		this.name = name;
	}
	public int getAge()
	{
		return age;
	}
	public void setAge(int age)
	{
		this.age = age;
	}
	public String toString()
	{
		return "姓名："+this.name+",年龄："+this.age;
	}
	
	public boolean equals(Object obj)
	{
		if(this == obj)
		{
			return true;
		}
		if(!(obj instanceof Person))
		{
			return false;
		}
		else 
		{
			Person per = (Person)obj;
			if(this.name.equals(per.getName()) && this.age == per.getAge())
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
}

public class ObjDemo03
{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		Object obj = null;
		obj =  new Person("刘兆清",26);
		Person per = new Person("刘兆清",26);
		System.out.println(per.equals(obj)?"是一类":"不是一类");
		System.out.println(per.toString());
		System.out.println(obj.toString());
		System.out.print("\n"+per);

	}

}
